<?php
/**
 * Created by PhpStorm.
 * User: Zhangxy
 * Date: 2018/10/15
 * Time: 16:34
 */

namespace App\Libraries;


use Monolog\Formatter\LineFormatter;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;


class LTLog
{

    /**
     * query logger
     * User: Zhangxy
     * Date: 2018-10-16
     * @return Logger
     */
    public static function queryLogger()
    {
        $name = 'query';
        $currentTime = time();
        $month = date('Ym', $currentTime);
        $day = date('d', $currentTime);
        $logger = new Logger($name);

        // 自定义目录
        $path = sprintf("%s/logs/%s_%s%s.log", storage_path(), $name, $month, $day);
        $cwStreamHandler = new StreamHandler($path, Logger::INFO, true, 0777);

        // 设置日志格式
        // 日志格式:使用laravel原有格式:
        // the default output format is "[%datetime%] %channel%.%level_name%: %message% %context% %extra%\n"
        $format = "[%datetime%] %message% \n";
        $formatter = new LineFormatter($format);
        $cwStreamHandler->setFormatter($formatter);

        $logger->pushHandler($cwStreamHandler);

        return $logger;
    }


}